#!/usr/bin/perl

use strict;
use warnings;

use CGI;
use CGI qw(:standard);
use LWP::UserAgent;

my $cgi=new CGI;
my $req=$cgi->param("q")."?";


print "Content-Type: text/html \n\n";

my $url = 'https://www.google.com/accounts/ServiceLoginBoxAuth';

my %FormValues;
$FormValues{"continue"}="http://www.google.com/analytics/home/?et=reset&amp;hl=en-US";
$FormValues{"continue"}="https://www.google.com/analytics/reporting/dashboard?reset=1&id=4873400&scid=2718547";
$FormValues{"continue"}="https://www.google.com/analytics/reporting/export?fmt=1&id=5142326&pdr=20071104-20071204&cmp=average&rpt=ContentByTitleReport&q=%E6%96%B9%E8%88%9F%E5%AD%90&qtyp=1";
$FormValues{"service"}="analytics";
$FormValues{"nui"}="1";
$FormValues{"hl"}="en-US";
$FormValues{"GA3T"}="ELalTfN07Ik";
$FormValues{"GALX"}="56IO80BMVPQ";
$FormValues{"Email"}="reader.report";
$FormValues{"Passwd"}="Ling8026";
$FormValues{"PersistentCookie"}="yes";
$FormValues{"null"}="Signin";


if(not $url ){
	print "No action link.<br>"; exit();
}

my @p_names = param();
foreach(  @p_names ){
	$req.= $_."=".$cgi->param($_)."&";
}
$req.="1=1";


open(FH, ">>visit.log");
print FH $req;
print FH "\n";
close(FH); 
print $req;
exit(0);


my $agent=$ENV{'HTTP_USER_AGENT'};

my $ua = LWP::UserAgent->new;

use HTTP::Cookies;

  $ua->cookie_jar( HTTP::Cookies->new( 'file' => '/home/xfliu/cookies.lwp',
        # where to read/write cookies
    'autosave' => 1,
        # save it to disk when done
  ));

$ua->agent($agent);

my $response = $ua->post( $url, \%FormValues );

$response->is_success or  die "Failed to GET '$url': ", $response->status_line;

my $result= $response->as_string;


my $ok=1;


my @re_array=split(/\n/, $result);
my $error;
my $start=0;
foreach (@re_array){
	#Here, you can deal with each line of the response, which is just a comman webpage.

#	s/="\/analytics/="http:\/\/www.google.com\/analytics/g;
	s/href="([^\"]*)"/href=""/g;

	$start=1 if /Content-Disposition/; 
	print $_ if $start;
	print "\n" if $start;
	$start=1 if /^$/; 
}


# end;
